package com.nova;

import com.nova.view.NovaButtonDialog;
import com.nova.view.NovaProgressDialog;
import com.nova.view.NovaTextDialog;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.Fragment;

/**
 * 基本fragment
 */
public  class BaseFragment extends Fragment {


	protected Activity mContext;
	protected Intent mIntent;
	
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		this.mContext = activity;
		//System.out.println("FirstFragment--onAttach");
	}
	

	private NovaProgressDialog progressDialog;

	/**
	 * 显示文本信息的加载框
	 */
	public void showProgressDialog(String text)
	{
		if (this.progressDialog == null)
			this.progressDialog = new NovaProgressDialog(mContext);
		this.progressDialog.setText(text);
		this.progressDialog.setCancelable(false);
		this.progressDialog.show();
	}

	/**
	 * 显示文本信息的加载框，通过boolean值决定对话框是否显示
	 */
	public void showProgressDialog(String text, boolean cancelable)
	{
		if (this.progressDialog == null)
			this.progressDialog = new NovaProgressDialog(mContext);
		this.progressDialog.setText(text);
		this.progressDialog.setCancelable(cancelable);
		this.progressDialog.show();
	}

	public void showProgressDialog(int text)
	{
		if (this.progressDialog == null)
			this.progressDialog = new NovaProgressDialog(mContext);
		this.progressDialog.setText(text);
		this.progressDialog.setCancelable(false);
		this.progressDialog.show();
	}

	public void showProgressDialog(int text, boolean cancelable)
	{
		if (this.progressDialog == null)
			this.progressDialog = new NovaProgressDialog(mContext);
		this.progressDialog.setText(text);
		this.progressDialog.setCancelable(cancelable);
		this.progressDialog.show();
	}

	/**
	 * 取消文本信息的加载框
	 */
	public void cancelProgressDialog()
	{
		if (this.progressDialog != null)
		{
			this.progressDialog.setCancelable(false);
			this.progressDialog.cancel();
		}
	}

	private NovaTextDialog textDialog;

	/**
	 * 显示文本信息
	 */
	public void showTextDialog(String text)
	{
		if (this.textDialog == null)
			this.textDialog = new NovaTextDialog(mContext);
		this.textDialog.setText(text);
		this.textDialog.show();
	}

	/**
	 * 显示数字信息
	 */
	public void showTextDialog(int text)
	{
		if (this.textDialog == null)
			this.textDialog = new NovaTextDialog(mContext);
		this.textDialog.setText(text);
		this.textDialog.show();
	}

	/**
	 * 取消文本信息对话框
	 */
	public void cancelTextDialog()
	{
		if (this.textDialog != null)
			this.textDialog.cancel();
	}

	private NovaButtonDialog buttonDialog;

	/**
	 * 显示文本信息按钮对话框
	 */
	public void showButtonDialog(String text)
	{
		if (this.buttonDialog == null)
			this.buttonDialog = new NovaButtonDialog(mContext);
		this.buttonDialog.setText(text);
		this.buttonDialog.show();
	}

	/**
	 * 显示数字信息按钮对话框
	 */
	public void showButtonDialog(int text)
	{
		if (this.buttonDialog == null)
			this.buttonDialog = new NovaButtonDialog(mContext);
		this.buttonDialog.setText(text);
		this.buttonDialog.show();
	}

	/**
	 * 取消按钮对话框
	 */
	public void cancelButtonDialog()
	{
		if (this.buttonDialog != null)
			this.buttonDialog.cancel();
	}

	/**
	 * 16进制字符串转换成10进制字符串
	 * 
	 * @param hexString
	 * @return
	 */
	public static final String hexStringToString(String hexString)
	{

		StringBuffer sb = new StringBuffer();

		for (int i = 0; i < hexString.length(); i = i + 2)
		{

			// System.out.println(hexString.substring(i, i + 2));

			String data = Integer.toString(Integer.parseInt(
					hexString.substring(i, i + 2), 16));
			if (data.length() == 1)
			{
				data = "0" + data;
			}

			sb.append(data);
		}
		return sb.toString();
	}

	/**
	 * 10进制字符串转换成16进制字符串
	 * 
	 * @param hexString
	 * @return
	 */
	public static final String stringToHexString(String data)
	{

		StringBuffer sb = new StringBuffer();

		for (int i = 0; i < data.length(); i = i + 2)
		{

			String hexData = Integer.toHexString(Integer.parseInt(data
					.substring(i, i + 2)));
			if (hexData.length() == 1)
			{
				hexData = "0" + hexData;
			}
			sb.append(hexData);
		}
		return sb.toString();
	}

	
	
	
}
